最初の一歩:
Create Procedure FindString(
@MyString nvarchar(50))
As
Begin
Select * From MyTable
Where Value = @MyString
End
クラスを作成します。
public class ReadData
{
public bool FindString(string myString)
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Server=..."; //Your connection string
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "FindString";
command.Parameters.AddWithValue("@MyString", myString);
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
return true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
return false;
}
}
クラスを使用します。例えば :
ReadData r = new ReadData();
if (r.FindString("Shahingg"))
MessageBox.Show("I Found it!");
else
MessageBox.Show("I can't Find it!");