當我想檢查是否存在於數據庫條目中的程序給我一個錯誤:如果在數據庫中存在錯誤值C#檢查
Keyword not supported: 'datasource'
我的代碼:
public bool FindString(string myString)
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "datasource=localhost;port=3306;username=admin;password=admin";
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "Create Procedure FindString(@MyString nvarchar(50)) as Begin Select * test.user Where Value = @MyString End";
command.Parameters.AddWithValue("@MyString", myString);
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
return true;
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
finally
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
return false;
}
而且代碼使用該類:
ReadData r = new ReadData();
if (r.FindString(textBox1.Text))
MessageBox.Show("I Found it!");
else
MessageBox.Show("I can't Find it!");