textbox
입력에서 데이터베이스 테이블을 검색하는 데이터베이스에서 쿼리를 실행하려고합니다. 나는 밖으로 나가 오류가 connection.Open()
에서 발생 볼 수있는 캐치을 촬영하면 내 코드데이터베이스에 연결 중 - connectString connect.Open() 오류
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Query
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void employeeBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.employeeBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.personnelDataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'personnelDataSet.employee' table. You can move, or remove it, as needed.
this.employeeTableAdapter.Fill(this.personnelDataSet.employee);
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
string connectionString = "Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;";
private void btnSearch_Click(object sender, EventArgs e)
{
string commandText = "SELECT employeeID, name, position, hourlyPayRate " +
"FROM dbo.employee WHERE name LIKE '%'+ @Name + '%'";
using (SqlConnection connection = new SqlConnection(connectionString))
{
//Create a SqlCommand instance
SqlCommand command = new SqlCommand(commandText, connection);
//Add the parameter
command.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = textBox1.Text;
//Execute the query
try
{
connection.Open();
command.ExecuteNonQuery();
}
catch
{
//Handle excepetion, show message to user...
MessageBox.Show("Error bitch!");
}
finally
{
connection.Close();
}
}
}
}
}
입니다. 이 오류는 나를 string connectionString = "Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;";
이에 문제가 있는지 궁금해하는하게 일어나는 동안이다 걸리는 I 나타나는 오류 :
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
의 아마 당신의 연결 문자열을
또 다른 방법은 다음과 같이 Web.config를 통해 데이터베이스를 연결하는 것입니다. 당신은 ssms있어? 연결 문자열을 확인할 수 있습니까? –
나는 ssms가 없다. 어떻게 확인할 수 있습니까? – Matt
연결 고리입니다. 복사 - 붙여 넣기를 통해 일반 연결을 방금 가져 왔습니다. 실제로 serveraddress 등을 채우십시오. – Matthijs