I’m going to edit textbox value.. but i saw there’s a problem
protected void btn_edit_Click(object sender, EventArgs e)
{
DatabaseConnector con = new DatabaseConnector().CreateInstance();
SqlCommand com = new SqlCommand("UPDATE tbl_BinCardManager SET ItemName = @ItemName WHERE ItemNo = @ItemNo");
com.Parameters.Add("@ItemName",sqlDbType.VarChar);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
ERROR 1:
The name ‘sqlDbType’ does not exist in the current context
ERROR 2:
‘ERPSystem.DatabaseConnector’ does not contain a definition for ‘Open’
and no extension method ‘Open’ accepting a first argument of type
‘ERPSystem.DatabaseConnector’ could be found (are you missing a using
directive or an assembly reference?)
My DBConnector Class is :
class DatabaseConnector
{
private DatabaseConnector databaseConnector;
private string connectionString = "Data Source=lernlap;Initial Catalog=ERPSystemDB;User ID=sa;Password=sa123";
public DatabaseConnector()
{
}
private SqlConnection connection;
private bool Connect()
{
try
{
connection = new SqlConnection(connectionString);
connection.Open();
return true;
}
catch(Exception) {
return false;
}
}
internal DatabaseConnector CreateInstance()
{
if (databaseConnector == null)
{
databaseConnector = new DatabaseConnector();
databaseConnector.Connect();
}
return databaseConnector;
}
C# is case sensetive… Try using intellisense.
The other errors may disappear if you correct the first one.
On a side note, you’re going to run into connection/memory leaks without proper resource handling. Personally, I use the
usingstatement to avoid the pitfalls.I’m not entirely certain what “DatabaseConnector” is, possible your own class, but you should probably be using SqlConnection instead, or possibly SqlDatabase.
Update: I’m not sure if the DBConnector class is supposed to be a singleton or a factory, or both – so I just simplified my answer to avoid using it. Ask another question with detail on how to create the pattern you’re looking for and provide the DBConnector class. I think it’s do-able, but I just don’t have enough info to fix what you have.