Do not use string concatenation for your sql variables! Use parameterized sql instead. Your column types should also be correct and use the native type, not the string representation. The parameters should also use the native values (not string representation) for each parameter.
This is a code fix that most likely can fix your problem but you need to change your schema to ensure that you are using native types. This will fix your problem where you are storing a localized string representation of a value instead of the native type. Here are my guesses as to the correct data type.
id
- should probably be an int marked with Identity
if you want the Db to auto generate this. In that case change the schema and do not pass a value in your insert.
table_no
- probably a varchar
, be sure to specify the correct length in the parameter.
gametime
- should probably be of type Time
, pass a TimeSpan to the value
localdate
- I recommend datetime2
but datetime
could also be used
money
- use decimal
and specify the precision and the scale in your schema. Be sure those match what you set on the parameter.
Adjusted code
const string sql = @"INSERT INTO stollar (id, table_no, gametime, localdate, money) VALUES (@id, @table_no, @gametime, @localdate, @money)";
using(SqlConnection conn = new SqlConnection(/*your connection string from app.config or web.config*/))
using(SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.Int){Value = int.Parse(txt1.Text)});
cmd.Parameters.Add(new SqlParameter("@table_no", SqlDbType.VarChar, 100){Value = gbox1.Text.Trim()});
cmd.Parameters.Add(new SqlParameter("@gametime", SqlDbType.Time){Value = TimeSpan.FromMinutes(int.Parse(time_hour.Text.Trim()) * 60 + int.Parse(time_minute.Text.Trim()))});
cmd.Parameters.Add(new SqlParameter("@localdate", SqlDbType.DateTime){Value = DateTime.Now});
cmd.Parameters.Add(new SqlParameter("@money", SqlDbType.Decimal){Precision = 10, Scale = 2, Value = decimal.Parse(txtbox_1.Text, CultureInfo.InvariantCulture)});
conn.Open();
cmd.ExecuteNonQuery();
}