Programmable Physics
Member
- Joined
- Sep 26, 2022
- Messages
- 16
- Programming Experience
- 1-3
I am using Northwind database in Sql Server.
I am using Stored Procedure to connect Visual Studio with Sql Server and draw data from database.
In CRUD operations, I am tring to write a SEARCH button that is using Stored Procedure.
Other CRUD buttons are working okay.
Search button is not bringing only specific relevant data from the database and display it in the datagridview
It does not give any error, only continues to not Filter and Search data, but display in the DataGridView all the irrelevant & relevant data there is in the customers in the database.
My Stored Procedure :
(...)
Relevant "Select" Part of Stored Procedure Code is this :
Search button code in my VS 2022 :
When button is clicked it does nothing but viewing all datas of all Customers.
I am using Stored Procedure to connect Visual Studio with Sql Server and draw data from database.
In CRUD operations, I am tring to write a SEARCH button that is using Stored Procedure.
Other CRUD buttons are working okay.
Search button is not bringing only specific relevant data from the database and display it in the datagridview
It does not give any error, only continues to not Filter and Search data, but display in the DataGridView all the irrelevant & relevant data there is in the customers in the database.
My Stored Procedure :
C#:
ALTER PROC [dbo].[benimprocedurum]
(
@Id int = null,
@CustomerID1 varchar(50) = null,
@CompanyName varchar(50) = null,
@ContactName varchar(50) = null,
@Country varchar(50) = null,
@Action varchar(50) = null
)
AS BEGIN
(...)
Relevant "Select" Part of Stored Procedure Code is this :
C#:
IF @Action = 'Select'
BEGIN
SELECT * FROM Customers WHERE CustomerID = @CustomerID1
END
END
END
Search button code in my VS 2022 :
C#:
private void AraBtn_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Lütfen Müşteri bilgilerini giriniz");
textBox1.Select();
return;
}
using (SqlConnection cn = new SqlConnection(baglanticumlesi))
{
using (SqlCommand cmd = new SqlCommand("benimprocedurum", cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Action", "Select");
cmd.Parameters.AddWithValue("@CustomerID1", textBox1.Text);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
}
Form1_Load(this, null);
}
When button is clicked it does nothing but viewing all datas of all Customers.