WriteValueInDataBase
WriteValueInDataBase
user code module > any sample code or tutorial how to write value in sqldatabase, thank you in advance
beginner
beginner
Tipu
Re: WriteValueInDataBase
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
Re: WriteValueInDataBase
Thank you Ciege, not sure why its not writing to db, using local db, i can read it but not able to write
public void AddCandidateName()
{
// Construct INSERT Command
_conn.Open();
SqlCommand cmd = new SqlCommand
("INSERT INTO RMQA(Name) VALUES ('aabb')",_conn);
_conn.Close();
}
public void AddCandidateName()
{
// Construct INSERT Command
_conn.Open();
SqlCommand cmd = new SqlCommand
("INSERT INTO RMQA(Name) VALUES ('aabb')",_conn);
_conn.Close();
}
Tipu
Re: WriteValueInDataBase
I don't see an execute in your code to actually run the command...
Code: Select all
cmd.ExecuteNonQuery();
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
Re: WriteValueInDataBase
Thank you Ciege to look into the code, after the adding the line i getting following error
Invalid object name 'RMQA'.
public void AddCandidateName()
{
// Construct INSERT Command
_conn.Open();
SqlCommand cmd = new SqlCommand
("INSERT INTO RMQA(Name) VALUES ('Tjessem')",_conn);
cmd.ExecuteNonQuery();
_conn.Close();
}
Invalid object name 'RMQA'.
public void AddCandidateName()
{
// Construct INSERT Command
_conn.Open();
SqlCommand cmd = new SqlCommand
("INSERT INTO RMQA(Name) VALUES ('Tjessem')",_conn);
cmd.ExecuteNonQuery();
_conn.Close();
}
Tipu
Re: WriteValueInDataBase
Is RMQA valid?
What is your entire exception text?
Are you using SQL Authentication or Windows Authentication in your connection?
Did you include the initial catalog in your connection?
Did you GOOGLE for your specific error?
What is your entire exception text?
Are you using SQL Authentication or Windows Authentication in your connection?
Did you include the initial catalog in your connection?
Did you GOOGLE for your specific error?
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
Re: WriteValueInDataBase
> Windows Authentication in my connection
> yes -initial catalog in my connection
>No- but going to -- GOOGLE for specific error?
Here is the new error i am getting --
Cannot insert the value NULL into column 'UniqueKey', table 'RMQA.dbo.Vendor'; column does not allow nulls. INSERT fails.
The statement has been terminated.
public void AddCandidateName()
{
SqlCommand dataCommand = new SqlCommand("INSERT Vendor (Name)VALUES ('first')",_conn);
_conn.Open();
dataCommand.ExecuteNonQuery();
_conn.Close();
}
> yes -initial catalog in my connection
>No- but going to -- GOOGLE for specific error?
Here is the new error i am getting --
Cannot insert the value NULL into column 'UniqueKey', table 'RMQA.dbo.Vendor'; column does not allow nulls. INSERT fails.
The statement has been terminated.
public void AddCandidateName()
{
SqlCommand dataCommand = new SqlCommand("INSERT Vendor (Name)VALUES ('first')",_conn);
_conn.Open();
dataCommand.ExecuteNonQuery();
_conn.Close();
}
Tipu
Re: WriteValueInDataBase
_conn =new SqlConnection("Data Source=(local)\\SQLExpress;Initial Catalog=RMQA;Integrated Security=SSPI");
Tipu
Re: WriteValueInDataBase
So what it sounds like to me is you need to spend some time reading about how to interact with SQL from within C# (or you development language of choice).
Each of the errors you are getting or have gotten can be easily discovered by doing some simple Google searches and reading.
I hope that is not too harsh, but it is appearing that you want to have other people do your work for you without you showing any interest in trying to discover the issues yourself. I hope you can understand...
Each of the errors you are getting or have gotten can be easily discovered by doing some simple Google searches and reading.
I hope that is not too harsh, but it is appearing that you want to have other people do your work for you without you showing any interest in trying to discover the issues yourself. I hope you can understand...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
Re: WriteValueInDataBase
Thank you for your input, it worked after adding the primary key value , total time spent on google around 72hrs to learn the function that add value in sql,
Thank you,
Beginner
Thank you,
Beginner
Tipu
Re: WriteValueInDataBase
Other comment...
Always use Command Parameters
It does the type conversion for you...
For example if you want to insert a DateTime into database, instead of converting it to a string add it as a command parameter!
Always use Command Parameters
It does the type conversion for you...
For example if you want to insert a DateTime into database, instead of converting it to a string add it as a command parameter!
Re: WriteValueInDataBase
Atom would you plz show me how does the code look like "Command Parameters
It does the type conversion for you..."
Thank you in advance,
Beginner
It does the type conversion for you..."
Thank you in advance,
Beginner
Tipu
Re: WriteValueInDataBase
SQLite example:
Code: Select all
'connect
objConnection = New SQLiteConnection(DbConnectionString)
objConnection.Open()
'update
objCommand = New SQLiteCommand(objConnection)
objCommand.CommandType = CommandType.Text
objCommand.CommandText = "UPDATE " & cTableName & " SET LASTUSED=$LASTUSED WHERE NAME=$NAME AND VERSION=$VERSION AND RC=$RC AND PLATFORM=$PLATFORM"
objCommand.Parameters.AddWithValue("$LASTUSED", DateTime.Now)
objCommand.Parameters.AddWithValue("$NAME", Product.Name)
objCommand.Parameters.AddWithValue("$VERSION", Product.Version)
objCommand.Parameters.AddWithValue("$RC", Product.RC)
objCommand.Parameters.AddWithValue("$PLATFORM", Product.Platform.ToString)
objCommand.ExecuteNonQuery()
'disconnect
objCommand.Dispose()
objConnection.Close()
objConnection.Dispose()
Re: WriteValueInDataBase
Atom, thank you so much for the sample code, i really needed this .
Thank you,
Beginner
Thank you,
Beginner
Tipu
Re: WriteValueInDataBase
Here is the scenario that i am trying to accomplish -
cycle one > test script produces some number like order id = 1112, I need to write this order id number in a empty row table called Result in sqlserver db.
the challenge i am facing in cycle two - when test execute in 2nd cycle - how to write orderid in new row instead of updating the existing field, same goes for 3rd cycle ...
Thank you in Advance
Beginner
cycle one > test script produces some number like order id = 1112, I need to write this order id number in a empty row table called Result in sqlserver db.
the challenge i am facing in cycle two - when test execute in 2nd cycle - how to write orderid in new row instead of updating the existing field, same goes for 3rd cycle ...
Thank you in Advance
Beginner
Tipu