connection class with SelectCommand.parameters.AddWithValue queries

41 Views Asked by At

The method for retrieving data from a connection class was decleared as

public void retrieveData(string command)

The SqlDataAdapter as

SqlDataAdapter da = new SqlDataAdapter(command, conn);

How do i execute my queries with SelectCommand.parameters.AddWithValue like the example below?

SqlDataAdapter da = new SqlDataAdapter("select count (*) from login2 where UserName =@user and PassWord =@pass", con);
da.SelectCommand.Parameters.AddWithValue("@user", txtUsername.Text);
da.SelectCommand.Parameters.AddWithValue("@pass", hp.HashMe(txtPassword.Text));

Do i need another method to handle the SelectCommand.parameters.AddWithValue? Do i modify the retrieveData method to handle it? How do i do this?

When i created the object of the class with the SelectCommand.parameters.AddWithValue i got an error that says its not valid in this context

CONN inputdata = new CONN();
inputdata.ExecData("insert into login2(UserName,PassWord,Name) values(@user,@pass,@name)");
inputdata.ExecData.SelectedCommand.Parameters.AddWithValue("@user", txtRUser.Text);
0

There are 0 best solutions below